home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / NIFTY / myCShell / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-24  |  4.3 KB  |  217 lines  |  [TEXT/KAHL]

  1. /*********************************************************
  2.  "cursor.c"
  3.  
  4.  by John A. Love, III [ Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.00
  7.  *********************************************************/
  8.  
  9.  
  10. #include <Retrace.h>
  11.  
  12. #include "protos"
  13.  
  14. #include "globals.h"
  15. #include "extern.h"
  16.  
  17. #include "floatingWindow.h"
  18.  
  19.  
  20.     
  21.  
  22. // Local prototype:
  23. pascal void    SpinTheBottle (void);        /* Cute, huh ?!!? */
  24.  
  25.  
  26.     Boolean                InWindow;
  27.     Handle                acurHdl;
  28.     MyVBLType            myVBLRec;
  29.     short                nbrGlobe;
  30.     extern DialogPtr    helpPtr;
  31.     extern WindowPeek    frontToolWindow, frontDocWindow;
  32.     
  33.  
  34.  
  35.     
  36. /* -----------------------
  37. ** Guess what this does ??
  38. ** ----------------------- */
  39.  
  40. void HandleCursor (void)    {
  41.  
  42.         GrafPtr                    savePort;
  43.         Point                    mouse;
  44.         CursHandle                CURS;
  45.         static CCrsrHandle        niftyColorCRSR = nil;
  46.         Boolean                    inFloatingWindow = false;
  47.         
  48.  
  49.     /* DAs & other applications roll their own: */
  50.     if (gCurrDA || !gInForeGround)    return;
  51.     
  52.     if (gFW == nil)        {
  53.         InitCursor();
  54.         if (niftyColorCRSR)        {
  55.             DisposCCursor(niftyColorCRSR);
  56.             niftyColorCRSR = nil;
  57.         }
  58.         return;
  59.     }
  60.     
  61.     if (frontToolWindow)    {
  62.         GetPort(&savePort);
  63.         SetPort((WindowPtr) frontToolWindow);
  64.         ;
  65.         GetMouse(&mouse);
  66.         if ( PtInRgn(mouse, ((WindowPtr)frontToolWindow)->visRgn) )
  67.             inFloatingWindow = true;
  68.         ;
  69.         SetPort(savePort);
  70.     }
  71.  
  72.     if (inFloatingWindow)    {
  73.         
  74.         if (!gMac2)        {
  75.             CURS = GetCursor(FLOAT);
  76.             if (CURS)    SetCursor(*CURS);
  77.             else        InitCursor();
  78.         }
  79.         
  80.         else if (niftyColorCRSR == nil)        {
  81.             niftyColorCRSR = GetCCursor(FLOAT);
  82.             if (niftyColorCRSR)        SetCCursor(niftyColorCRSR);
  83.             else    {
  84.                 CURS = GetCursor(FLOAT);
  85.                 if (CURS)    SetCursor(*CURS);
  86.                 else        InitCursor();
  87.             }
  88.         } /* end: gMac2 and NO color CRSR */
  89.             
  90.     }
  91.     
  92.     else    /* NOT in Floating Window */    {
  93.     
  94.         if (niftyColorCRSR)        {
  95.             DisposCCursor(niftyColorCRSR);
  96.             niftyColorCRSR = nil;
  97.         }
  98.  
  99.         if (frontDocWindow)        {
  100.  
  101.             GetMouse(&mouse);
  102.             if ( PtInRgn(mouse, ((WindowPtr)frontDocWindow)->visRgn) )    {
  103.     
  104.                 if (helpPtr == (WindowPtr)frontDocWindow)        InitCursor();
  105.                 else    {        // NOT Pillera's Help Window.
  106.         
  107.                     InitCursor();
  108.         
  109.         
  110.                 }    /* NOT Pillera's Help Window */
  111.  
  112.             }
  113.             else    /* !PtInRgn() */    InitCursor();
  114.             
  115.         }
  116.         else   /* NO frontDocWindow */    InitCursor();
  117.         
  118.     } /* NOT in Floating Window */
  119.  
  120. }    /* HandleCursor */
  121.  
  122.  
  123.  
  124. /* =============================
  125. ** Round-and-around she goes ...
  126. ** ============================= */
  127.  
  128. void    InstallVBLTask (short rsrcID)    {
  129.  
  130.         CursHandle    watch;
  131.         short        ignore;
  132.  
  133.  
  134.     acurHdl = GetResource('acur', rsrcID);
  135.     if (acurHdl == nil)
  136.     {
  137.         watch = GetCursor(watchCursor);
  138.         SetCursor(*watch);            /* Reset afterwards by my HandleCursor proc. */
  139.     }    /* acurHdl = nil */
  140.     else
  141.     {
  142.         nbrGlobe = (*((acurHandle)acurHdl))->nbrCursors;
  143.         ;
  144.         myVBLRec.CurrA5 = (long)CurrentA5;
  145.         myVBLRec.MyVBL.vblAddr = (ProcPtr)&SpinTheBottle;
  146.         myVBLRec.MyVBL.vblCount = 10;        /* Six times every second. */
  147.         myVBLRec.MyVBL.qType = vType;
  148.         myVBLRec.MyVBL.vblPhase = 0;
  149.         ;
  150.         ignore = VInstall( (QElemPtr)&(myVBLRec.MyVBL) );
  151.  
  152.     }    /* else */
  153.  
  154. }    /* InstallVBLTask */
  155.  
  156.  
  157.  
  158. void    RemoveVBLTask (void)    {
  159.  
  160.         short            ignore;
  161.         extern long        Sleep;
  162.  
  163.  
  164.     if (acurHdl != nil)    ignore = VRemove( (QElemPtr)&myVBLRec.MyVBL );
  165.     acurHdl = nil;                    /* Mark as gone. */
  166.  
  167.     /* CURSor reset later by "HandleCursor". */
  168.     Sleep = 1;                        /* ... so this happens under Multifinder. */
  169.  
  170. }    /* RemoveVBLTask */
  171.  
  172.  
  173.  
  174. /* =======================
  175. ** My spinning CURSor Task
  176. ** ======================= */
  177.  
  178. pascal void    SpinTheBottle (void)    {    /* Cute, huh ?!!? */
  179.  
  180.         CursHandle        globe;
  181.         short            globeID;
  182.  
  183.  
  184.     asm    {                            // PushA5()
  185.         move.l    a5, -(sp)
  186.     }
  187.  
  188.     asm    {                            // GetMyA5()
  189.         // Access my Globals by fetching the value of A5 we've stored
  190.         // before the VBLTask and then put it into A5.
  191.         //
  192.         // We know that when the VBL task is called, A0 will point to it.
  193.         // Therefore, the value of A5 that we stored will be at - 4(A0),
  194.         // which is immediately below the VBL Task in our data block.
  195.         move.l    -4(a0), a5
  196.     }
  197.  
  198.     globeID = HiWord( ( **((acurHandle)acurHdl) ).cursorIDs[nbrGlobe - 1] );
  199.     globe = GetCursor(globeID);
  200.     if (globe != nil)    SetCursor(*globe);
  201.  
  202.     nbrGlobe = nbrGlobe - 1;        /* Reset stuff for next time ... */
  203.     if (nbrGlobe == 0)    nbrGlobe = (*(acurHandle)acurHdl)->nbrCursors;
  204.     ;
  205.     myVBLRec.MyVBL.vblCount = 10;
  206.  
  207.     asm    {                            // PopA5()
  208.         move.l    (sp)+, a5
  209.     }
  210.  
  211. }    /* SpinTheBottle */
  212.  
  213.  
  214.  
  215.  
  216. /*    { end file "cursor.c" }  */
  217.